package com.zbkj.admin.controller.platform;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zbkj.common.annotation.LogControllerAnnotation;
import com.zbkj.common.enums.MethodType;
import com.zbkj.common.model.admin.SystemAdmin;
import com.zbkj.common.page.CommonPage;
import com.zbkj.common.request.ArticleRequest;
import com.zbkj.common.request.ArticleSearchRequest;
import com.zbkj.common.request.PageParamRequest;
import com.zbkj.common.response.ArticleInfoResponse;
import com.zbkj.common.response.ArticleResponse;
import com.zbkj.common.result.CommonResult;
import com.zbkj.service.service.*;
import com.zbkj.service.util.BrandUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import jdk.nashorn.internal.ir.annotations.Ignore;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 测试 前端控制器
 +----------------------------------------------------------------------
 */
@Slf4j
@RestController
@Ignore
@RequestMapping("api/admin/platform/brand/test")
@Api(tags = "测试")
public class TestController {

    @Autowired
    private BrandService brandService;

    @Autowired
    private SystemAdminService systemAdminService;

    @Autowired
    private WeatherService weatherService;
    @Autowired
    private PaidMemberOrderService paidMemberOrderService;



    @ApiOperation(value = "缓存品牌商信息")
    @RequestMapping(value = "/addCache", method = RequestMethod.POST)
    public CommonResult<String> addCache() {
        // 缓存品牌商信息
        brandService.cacheBrandInfo();
        return CommonResult.success();
    }

    @ApiOperation(value = "检查品牌商")
    @RequestMapping(value = "/checkBrand", method = RequestMethod.POST)
    public CommonResult<String> checkBrand() {

        Map<Integer, List<String>> map = new HashMap<>();
        map.put(0, Arrays.asList("https://zfb-platform.xingtu-group.com", "https://zfb-front.xingtu-group.com"));
        map.put(37, Arrays.asList("https://cr-admin.brand.xingtu-group.com", "https://cr-merchant.brand.xingtu-group.com", "https://cr.brand.xingtu-group.com"));
        map.put(115, Arrays.asList("https://xz-admin.brand.xingtu-group.com", "https://xz-merchant.brand.xingtu-group.com", "https://xz.brand.xingtu-group.com"));
        map.put(116, Arrays.asList("https://pn-admin.brand.xingtu-group.com", "https://pn-merchant.brand.xingtu-group.com", "https://pn.brand.xingtu-group.com"));
        map.put(132, Arrays.asList("https://ls-admin.brand.xingtu-group.com", "https://ls-merchant.brand.xingtu-group.com", "https://ls.brand.xingtu-group.com"));
        map.put(130, Arrays.asList("https://ll-admin.brand.xingtu-group.com", "https://ll-merchant.brand.xingtu-group.com", "https://ll.brand.xingtu-group.com"));
        map.put(281, Arrays.asList("https://xash-admin.brand.xingtu-group.com", "https://xash-merchant.brand.xingtu-group.com", "https://xash.brand.xingtu-group.com"));
        map.put(282, Arrays.asList("https://zmgj-admin.brand.xingtu-group.com", "https://zmgj-merchant.brand.xingtu-group.com", "https://zmgj.brand.xingtu-group.com"));
        map.put(280, Arrays.asList("https://jk-admin.brand.xingtu-group.com", "https://jk-merchant.brand.xingtu-group.com", "https://jk.brand.xingtu-group.com"));
        map.put(0, Arrays.asList("https://zfb-test-admin.brand.xingtu-group.com", "https://zfb-test-merchant.brand.xingtu-group.com", "https://zfb-test.brand.xingtu-group.com"));
        map.put(16, Arrays.asList("https://brand-test-admin.brand.xingtu-group.com", "https://brand-test-merchant.brand.xingtu-group.com", "https://brand-test.brand.xingtu-group.com"));
        map.put(283, Arrays.asList("https://msfn-admin.brand.xingtu-group.com", "https://msfn-merchant.brand.xingtu-group.com", "https://msfn.brand.xingtu-group.com"));
        map.forEach((id, urls) -> {
            for (String url : urls) {
                Integer idTmp = brandService.getBrandId(url);
                if (idTmp != null && idTmp.equals(id)) {
                    System.out.println("验证成功，" + id + "|" + idTmp + "|" + url);

                } else {
                    System.out.println("验证失败，" + id + "," + url);
                }
            }
        });

        return CommonResult.success();
    }

    @ApiOperation(value = "检查品牌商")
    @RequestMapping(value = "/checkBrandOld", method = RequestMethod.POST)
    public CommonResult<String> checkBrandOld() {
        Integer brandIdByUrl = BrandUtil.getBrandIdByUrlOld();
        System.out.println("brandIdByUrl = " + brandIdByUrl);
        return CommonResult.success();
    }

    @ApiOperation(value = "检查品牌商")
    @RequestMapping(value = "/checkBrandNew", method = RequestMethod.POST)
    public CommonResult<String> checkBrandNew() {
        String url = "https://xash-admin.brand.xingtu-group.com";
        Integer brandIdByUrl = BrandUtil.getBrandIdByUrl();
        System.out.println("brandIdByUrl = " + brandIdByUrl);
        return CommonResult.success();
    }

    @ApiOperation(value = "天气")
    @RequestMapping(value = "/testWeather", method = RequestMethod.POST)
    public CommonResult<String> testWeather() {
        List<String> list = Arrays.asList("101240404");
        weatherService.pullWeather(list);
        log.info("拉取天气定时任务完成");
        return CommonResult.success();
    }

    @ApiOperation(value = "赠送余额任务测试")
    @RequestMapping(value = "/testGiftBalanceTask", method = RequestMethod.POST)
    public CommonResult<String> testGiftBalanceTask() {
        log.info("赠送余额任务测试");
        paidMemberOrderService.giftBalanceTask();
        return CommonResult.success();
    }

}



